<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
  <div id="root"></div>
  <script>
    //v-once 让某个元素标签只渲染一次
    //ref 获取dom节点/组件引用
    const app = Vue.createApp({
      data() {
        return {
          count: 1
        }
      },
     /*  provide: {
        count: 1
      }, */
      provide() {
        return {
          count: this.count
        }
      },
      mounted() {
        // this.$refs.count.innerHTML='hello'
        this.$refs.hello.sayHello()
      },
      // template:`<div @click="count+=1" v-once>{{count}}</div>`
      // template:`<div ref="count">{{count}}</div>`
      template: `<hello ref="hello" /><button @click="count+=1">add</button>`
    });

    app.component('hello', {
      // props:['count'],
      methods: {
        sayHello() {
          alert('hello')
        }
      },
      template: `<helloChild />`
    });
    app.component('helloChild', {
      // props:['count'],
      inject: ['count'],
      template: `<div>{{count}}</div>`
    });

    const vm = app.mount('#root');
  </script>
</body>

</html>